%include "arch/x86/boot.inc"
[bits 16]
section mbr vstart=0x7c00
start:
    jmp entry
    db 0x90
    db "LBHOEM00"
    dw 512
    db 1
    dw 512
    db 2
    dw 0
    dw 0
    db 0xF8
    dw 0
    dw 0x003F
    dw 0x00FF
    dd 0x0000003F
    dd 0x00000800
    dd 0x00000100
    dw 0x0000
    dw 0
    dd 2
    dw 1
    dw 6
    resb 12
    db 0x80
    db 0
    db 0x29
    dd 0x93FA9B01
    db "NONAMETHERE"
    db "FAT32   "
entry:
    cli
    cld
    mov ax,cs
    mov ds,ax
    mov es,ax
    mov ss,ax
    xor sp,sp
    mov bp,sp
    call readdisk_m16
    jmp LOADER_BASE_ADDR
readdisk_m16:
    mov al,LOADER_SECTOR_NUMBER
    mov dx,01f2h
    out dx,al
    mov eax,LOADER_START_SECTOR
    mov dx,01f3h
    out dx,al
    shr eax,8
    mov dx,01f4h
    out dx,al
    shr eax,8
    mov dx,01f5h
    out dx,al
    shr eax,8
    and al,0fh
    or al,0e0h
    mov dx,01f6h
    out dx,al
    mov al,20h
    mov dx,01f7h
    out dx,al
    .wait_loop:
        nop
        in al,dx
        and al,88h
        cmp al,8
        jnz .wait_loop
    xor ax,ax
    mov es,ax
    mov cx,LOADER_SECTOR_NUMBER * 0x100
    mov di,LOADER_BASE_ADDR
    mov dx,01f0h
    rep insw
    ret
    times 446-($-$$) db 0
DPT:
    ;use GPT Signature
    dd 0x20000
    dd 0xFFFFFFEE
    dd 1
    dd 0xFFFFFFFF
    times 48 db 0
    dw 0xaa55